package com.trade.common.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * Class Description:
 *
 * @Version v1.0 2017/11/1 0:59
 * @JDK version 1.8.0_51
 * @Author zfb
 */
public class TestString {
    public static void main(String[] args) {
        System.out.println("请输入字符串长度:");
        Scanner s = new Scanner(System.in);
        int strLength = s.nextInt();
        System.out.println("请输入字符串:");
        s = new Scanner(System.in);
        String str = s.nextLine();
        System.out.println(str+"============"+strLength);
        System.out.println("字符种类个数："+printStr(str));
    }
    private static int printStr(String s){
        Map<String,Integer> map=new HashMap<>();

        for(char ch : s.toCharArray()){
            String ss=String.valueOf(ch);
            Integer count=map.get(ss);
            if(count==null){
                count=1;
            }
            map.put(ss,count); //map相同的键值会去重复
        }
        return map.size();
    }
}
